package com.corpgovernment.organization.dataloader.db;

import com.corpgovernment.organization.entity.db.MbLandmark;
import com.corpgovernment.organization.mapper.MbLandmarkMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

@Component
public class LandmarkLoader {


	@Autowired
	private MbLandmarkMapper landmarkMapper;

	/**
	 * 批量插入
	 *
	 * @param insertList
	 * @return
	 */
	public boolean insertBatch(List<MbLandmark> insertList) {
		insertList.forEach(landmarkMapper::insertSelective);
		return true;
	}

	public boolean insertBatchNew(List<MbLandmark> insertList) {
		landmarkMapper.insertList(insertList);
		return true;
	}

	/**
	 * 批量更新
	 *
	 * @param updateList
	 * @return
	 */
	public boolean updateBatch(List<MbLandmark> updateList) {
		updateList.forEach(landmarkMapper::updateByPrimaryKeySelective);
		return true;
	}

	/**
	 * 通用查询
	 *
	 * @param queryParam
	 * @return
	 */
	public List<MbLandmark> select(MbLandmark queryParam) {
		if (queryParam == null) {
			return new ArrayList<>();
		}
		queryParam.setIsDeleted(false);
		return landmarkMapper.select(queryParam);
	}

	/**
	 * 根据组织id查询
	 *
	 * @param orgId
	 * @return
	 */
	public List<MbLandmark> listByOrgId(String orgId) {
		MbLandmark query = new MbLandmark();
		query.setOrgId(orgId);
		return this.select(query);
	}

	/**
	 * 	根据ID业务删除地标
	 */
	public void del(List<Long> ids) {
		Example example = new Example(MbLandmark.class);
		example.createCriteria().andIn("id", ids);
		MbLandmark update = new MbLandmark();
		update.setIsDeleted(Boolean.FALSE);
		landmarkMapper.updateByExample(update, example);
	}

	/**
	 * 	根据ID业务删除地标
	 */
	public void delByOrgId(List<String> orgIds) {
		Example example = new Example(MbLandmark.class);
		example.createCriteria().andIn("orgId", orgIds);
		MbLandmark update = new MbLandmark();
		update.setIsDeleted(Boolean.FALSE);
		landmarkMapper.updateByExample(update, example);
	}
}
